<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加产品分类</title>
<!-- <style type="text/css">
    .uploader-blank{padding-top: 15px; width:158px;}
    .uploader-list{margin-bottom: 10px; position: relative;}
    .uploader-list img{height: 112px; width: 145px; border:#ccc 1px solid; padding: 5px;}
</style> -->
</head>
<body>
<div class="pd-20">
  <form action="" method="post" class="form form-horizontal" name="form1" id="form1">
    <div class="row cl">
        <input type="hidden" value="0" name="gc_parent_id" id="gc_parent_id">
        <label class="form-label col-3"><span class="c-red">*</span>分类名称：</label>
        <div class="formControls col-6 s-msg">
            <input type="text" class="input-text" placeholder="分类名称" id="gc_name" name="gc_name" nullmsg="分类名称不能为空！" datatype="s1-16">
        </div>
        <div class="col-2"> </div>
    </div>
    <div class="row cl" id="f_classblank" style="display: none;">
        <label class="form-label col-3">分类图标：</label>
        <div class="formControls col-5">
            <span class="select-box">
                <select name="f_class" id="f_class" class="select">
                    <option value="" selected="">更改上级分类</option>
                    
                </select>
            </span> 
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-3">类别</label>
        <div class="formControls col-3 s-msg">
            <div class="radio-box">
                <label class="lh-26">
                    <input type="radio" name="gc_type" value="1" >普通商品
                </label>
            </div>
            <div class="radio-box">
                <label class="lh-26">
                    <input type="radio" name="gc_type" value="2" checked>自营商品
                </label>
             </div>
        </div>
        
    </div>  
    <div class="row cl">
        <label class="form-label col-3">缩略图：</label>
        <div class="formControls col-5" >
            
            <div class="l mb-10 fj-img" id="imgslt" >
                
            </div>
    
            <i class="Hui-iconfont fj-img-btn" onclick="_open('缩略图','article-imageupload.html?type=image&idname=imgslt&api=gc&single=1&inputname=gc_icon','90%','90%',true)">&#xe610;</i>
    

             
        </div>
    </div>
    <!-- <div class="row cl">
        <label class="form-label col-3">缩略图：</label>
        <div class="formControls col-10" >
            <div class="l mb-10 fj-img" id="imgslt" >
                
            </div>
            
            <i class="Hui-iconfont fj-img-btn" onclick="_open('缩略图','article-imageupload.html?type=image&idname=imgslt&api=gc&single=1&inputname=gc_icon','750px','470px',true)">&#xe610;</i>

            
        </div>
    </div> -->
    <!-- <div class="row cl">
        <label class="form-label col-3">分类图标：</label>
        <div class="formControls col-5">
            <div id="uploader-demo">
                <div id="fileList" class="uploader-list">
                </div>
                <div id="filePicker" class="btn btn-secondary radius" onclick="_open('分类图标','article-imageupload.html?type=image&idname=fileList&api=gc&single=1&inputname=gc_icon','710px','470px',true)">上传图标</div>
            </div>
        </div>
        <div class="col-5"> </div>
    </div> -->
    <div class="row cl">
        <label class="form-label col-3">备注：</label>
        <div class="formControls col-8">
            <textarea name="gc_description" id="gc_description" cols="" rows="" class="textarea"  placeholder="说点什么...最少输入3个字符"  dragonfly="true" onKeyUp="textarealength(this,100)"></textarea>
            <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row cl">
        <div class="col-9 col-offset-3">
            <input class="btn btn-primary radius" type="submit" id="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
        </div>
    </div>
    </form>
</div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 

<script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script>
<script type="text/javascript" src="js/s.js"></script> 
<script type="text/javascript">
$(function(){
    
    var parentid=getUrlParam('parentid');//添加分类的父分类id
    var editid=getUrlParam('editid');//编辑分类id
    if(parentid==null && editid==null){
        $("#form1").attr("action", API_GOODSCLASS);
    }

    

    if(parentid!=null){
        console.log(parentid);
        $("#form1").attr("action", API_GOODSCLASS);
        $("input[name='gc_parent_id']").val(parentid);
        $("#f_classblank").show();
        $.getJSON(API_GOODSCLASS,function(data){
            if(!checkStatus(data)) return;
            for(i=0; i<data.datas.length; i++){
                if(data.datas[i].gc_id==parentid){
                    $("#f_class").append("<option value='"+data.datas[i].gc_id+"' selected>"+data.datas[i].gc_name+"</option>");
                }else{
                    $("#f_class").append("<option value='"+data.datas[i].gc_id+"'>"+data.datas[i].gc_name+"</option>");
                }
            }
            $("#f_class").bind("change",function(){
                var id=$(this).val();
                $("input[name='gc_parent_id']").val(id);
            })
        })
    }



    if(editid!=null){
        
        var eidturl=API_GOODSCLASS+"?id="+editid;

        $.getJSON(eidturl,function(data){
            if(!checkStatus(data)) return;//判断登录

            if(data.datas==''){
                layer.msg("数据加载错误", {icon:2,time:1000});
            }else{
                $("#gc_name").val(data.datas.gc_name);
                $("#gc_description").val(data.datas.gc_description);
                $("#form1").attr("action", API_GOODSCLASS);
                $("#form1").attr("action", eidturl);
                $("input[name='gc_type'][value="+data.datas.gc_type+"]").attr("checked",true);

                // if(data.datas.gc_icon!==""){
                //     $("#fileList").html('<img src="'+data.datas.gc_icon+'">');
                // }

                // if(data.datas.gc_icon!==""){
                //     console.log(data.datas.gc_icon);
                //     $("#imgslt").html('<img src="'+data.datas.gc_icon+'"><i class="icon Hui-iconfont fun-img-del" data-id="#imgslt" data-inputname="gc_icon"></i><input type="hidden" name="gc_icon" value="'+data.datas.gc_icon+'">');
                // }

                        if(data.datas.gc_icon!==""){
                            console.log(data.datas.gc_icon);
                            $("#imgslt").html('<img src="'+data.datas.gc_icon+'"><i class="icon Hui-iconfont fun-img-del" data-id="#imgslt" data-inputname="gc_icon"></i><input type="hidden" name="gc_icon" value="'+data.datas.gc_icon+'">');
                        }

            }
            
        })
    }


    Validformsubmit("#form1");
});



</script>
</body>
</html>